home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir42 / c7105.zip / RPTGRPS.TPX < prev    next >
Text File  |  1994-03-02  |  63KB  |  1,381 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                               RptGrps.TPX              │Version: 3007.105│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│ReportDataDeclares    GROUP                                               │
  7. #!│RptRedirectGroup      GROUP                                               │
  8. #!│RptGetLookupRecords   GROUP                                               │
  9. #!│RptGetRelatedRecords  GROUP                                               │
  10. #!│PrintDetail           GROUP                                               │
  11. #!│RptTotalRoutines      GROUP                                               │
  12. #!│DoTallyTotals         GROUP                                               │
  13. #!│DoResetTotals         GROUP                                               │
  14. #!│TallyTotals           GROUP                                               │
  15. #!│ResetTotals           GROUP                                               │
  16. #!│SaveFooterFields      GROUP                                               │
  17. #!│SaveFooterRoutine     GROUP                                               │
  18. #!│SaveFooterAssigns     GROUP                                               │
  19. #!│PrintFooterFields     GROUP                                               │
  20. #!│PrintFooterRoutine    GROUP                                               │
  21. #!│RestoreFooterFields   GROUP                                               │
  22. #!│RestoreFooterRoutine  GROUP                                               │
  23. #!│ReportFormulas        GROUP                                               │
  24. #!│RptRecordFilter       GROUP                                               │
  25. #!│GroupBreakNumber      GROUP                                               │
  26. #!│PrimaryGroupBreak     GROUP                                               │
  27. #!│FindGroupBreaks       GROUP                                               │
  28. #!│SecondaryGroupBreak   GROUP                                               │
  29. #!│BreakFooterRoutines   GROUP                                               │
  30. #!│BreakHeaderRoutines   GROUP                                               │
  31. #!│GroupBreakFooter      GROUP                                               │
  32. #!│GroupBreakHeader      GROUP                                               │
  33. #!│MultiUpLabelBuild     GROUP                                               │
  34. #!│MultiUpLabelReset     GROUP                                               │
  35. #!│PrintDanglingLabels   GROUP                                               │
  36. #!│RptAbortKey           GROUP                                               │
  37. #!│RptSetFlags           GROUP                                               │
  38. #!│RptFindFile           GROUP                                               │
  39. #!│ReportErrorCheck      GROUP                                               │
  40. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  41. #!│Version   Comments                                                        │
  42. #!│────────  ────────────────────────────────────────────────────────────────│
  43. #!│3007.000  Release of CDD3 version 3007 templates                          │
  44. #!│3007.102  Repaired %PrintFooterRoutine GROUP                              │
  45. #!│          Repaired %PrintFooterFields GROUP                               │
  46. #!│3007.103  Repaired %FindGroupBreaks GROUP                                 │
  47. #!│3007.105  Repaired %RptRedirectGroup GROUP                                │
  48. #!│          Repaired %PrimaryGroupBreak GROUP                               │
  49. #!│          Repaired %FindGroupBreaks GROUP                                 │
  50. #!└──────────────────────────────────────────────────────────────────────────┘
  51. #!
  52. #!***************************************************************************
  53. #GROUP(%ReportDataDeclares)                     #!Internal data declarations
  54. TempFile           CSTRING(65),AUTO            #<!Temporary filename variable
  55.   #IF(%RedirectProc AND %ViewProc)
  56. SavePath           STRING(64),AUTO             #<!Temporary path save variable
  57. TempPath           STRING(64),AUTO             #<!Temporary directory variable
  58.   #ENDIF
  59.   #FIX(%File,%Primary)
  60. %FilePre::PRINTED       BYTE,AUTO              #<!%Primary recs printed flag
  61.   #FOR(%Secondary)
  62.     #IF(%SecondaryType = '1:MANY')
  63.       #FIX(%File,%Secondary)
  64. %FilePre::PRINTED       BYTE,AUTO              #<!%Secondary recs printed flag
  65.     #ENDIF
  66.   #ENDFOR
  67.   #IF(%ReportGroupExist)
  68. BreakLevel         BYTE,AUTO                    #<!Group break level flag
  69.   #ENDIF
  70.   #FOR(%ReportGroup)                            #!Group break fields
  71.     #SET(%BreakField,%ReportGroup)
  72.     #INSERT(%RptFindFile)
  73.     #IF(%Primary = %FoundFile)
  74.       #FIX(%File,%FoundFile)
  75.       #FIX(%Key,%PrimaryKey)
  76.     #ELSE
  77.       #FIX(%Secondary,%FoundFile)
  78.       #FIX(%File,%SecondaryTo)
  79.       #FIX(%Relation,%Secondary)
  80.       #SET(%TempKey,%RelationKey)
  81.       #FIX(%File,%FoundFile)
  82.       #FIX(%Key,%TempKey)
  83.     #ENDIF
  84.     #FOR(%KeyField)                             #!Build BreakFilesQueue
  85.       #FIX(%Field,%KeyField)                    #! and declare group break
  86.       #SET(%Temp,%KeyField)                     #! save fields at same time
  87.       #IF(NOT INSTRING(%Temp,%BreakFieldsQueue,1,1))
  88.         #SET(%BreakFieldsQueue,(%BreakFieldsQueue & %Temp & ','))
  89.         #IF(%FieldType = 'GROUP')
  90. BRK::%KeyField     STRING(SIZE(%KeyField)) #<!Group break save field
  91.         #ELSE
  92. BRK::%KeyField     LIKE(%KeyField)        #<!Group break save field
  93.         #ENDIF
  94.       #ENDIF
  95.       #IF(%KeyField = %ReportGroup)             #!End of break fields
  96.         #BREAK                                  #! for this Group Break
  97.       #ENDIF
  98.     #ENDFOR
  99.   #ENDFOR
  100.   #SET(%Counter1,%NULL)
  101.   #FOR(%ReportTotal)                            #!AVERAGE total fields
  102.     #SET(%Counter1,(%Counter1 + 1))
  103.     #IF(%ReportTotalType = 'LOW')
  104. %ReportTotal::Reset  BYTE(1)
  105.     #ELSIF(%ReportTotalType = 'AVERAGE')
  106.       #IF(INSTRING('[',%ReportTotalField,1,1)) #!Check for array element
  107.         #SET(%ArrayField,(SUB(%ReportTotalField,1,INSTRING('[',%ReportTotalField,1,1)-1)))
  108. %ReportTotal::Cnt::%ArrayField::%Counter1   LONG #<!Average total count
  109. %ReportTotal::Sum::%ArrayField::%Counter1   REAL #<!Average total sum
  110.       #ELSE
  111. %ReportTotal::Cnt::%ReportTotalField   LONG    #<!Average total count
  112. %ReportTotal::Sum::%ReportTotalField   REAL    #<!Average total sum
  113.       #ENDIF
  114.     #ENDIF
  115.   #ENDFOR
  116.   #IF(%ReportSaveExist)
  117.     #SET(%Counter1,%NULL)
  118.     #SET(%Counter2,%NULL)
  119.     #FOR(%ReportSave)                           #!Footer save fields
  120.       #SET(%Counter1,(%Counter1 + 1))
  121.       #FOR(%ReportSaveField)
  122.         #SET(%Counter2,(%Counter2 + 1))
  123.         #SET(%BreakField,%ReportSaveField)
  124.         #INSERT(%RptFindFile)
  125.         #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  126.           #IF(INSTRING('[',%ReportSaveField,1,1)) #!Check for array element
  127.             #SET(%ArrayField,(SUB(%ReportSaveField,1,INSTRING('[',%ReportSaveField,1,1)-1)))
  128.             #FIX(%File,%FoundFile)
  129.             #FIX(%Field,%ArrayField)
  130.             #IF(%FieldType = 'STRING' OR %FieldType = 'CSTRING' OR %FieldType = 'PSTRING')
  131. SAV1::%ReportSave::%Field::%Counter1::%Counter2   STRING(SIZE(%ReportSaveField)),AUTO
  132. SAV2::%ReportSave::%Field::%Counter1::%Counter2   STRING(SIZE(%ReportSaveField)),AUTO
  133.                                                #<!%ReportSave Footer save fields
  134.             #ELSE
  135. SAV1::%ReportSave::%Field::%Counter1::%Counter2   REAL,AUTO
  136. SAV2::%ReportSave::%Field::%Counter1::%Counter2   REAL,AUTO
  137.                                                #<!%ReportSave Footer save fields
  138.            #ENDIF
  139.           #ELSE
  140.             #FIX(%File,%FoundFile)
  141.             #FIX(%Field,%ReportSaveField)
  142.             #IF(%FieldType = 'GROUP')
  143. SAV1::%ReportSave::%ReportSaveField   STRING(SIZE(%ReportSaveField)),AUTO
  144. SAV2::%ReportSave::%ReportSaveField   STRING(SIZE(%ReportSaveField)),AUTO
  145.                                                #<!%ReportSave Footer save fields
  146.             #ELSE
  147. SAV1::%ReportSave::%ReportSaveField   LIKE(%ReportSaveField),AUTO
  148. SAV2::%ReportSave::%ReportSaveField   LIKE(%ReportSaveField),AUTO
  149.                                                #<!%ReportSave Footer save fields
  150.             #ENDIF
  151.           #ENDIF
  152.         #ENDIF
  153.       #ENDFOR
  154.     #ENDFOR
  155.   #ENDIF
  156.   #IF(%PageTotals = 'YES')
  157. SAV::LineCounter   SHORT                       #<!Line counter save
  158.   #ENDIF
  159.   #IF(%ReportLabel)                             #!Multi-up label USE variables
  160. SAV::LabelCounter BYTE                         #<!Multi-up label counter
  161.     #SET(%Counter1,%NULL)
  162.     #FOR(%ReportLabelField)
  163.       #SET(%Counter1,(%Counter1 + 1))
  164.       #IF(INSTRING('[',%ReportLabelField,1,1)) #!Check for array element
  165.         #SET(%ArrayField,(SUB(%ReportLabelField,1,INSTRING('[',%ReportLabelField,1,1)-1)))
  166.         #SET(%BreakField,%ReportLabelField)
  167.         #INSERT(%RptFindFile)
  168.         #FIX(%File,%FoundFile)
  169.         #FIX(%Field,%ArrayField)
  170.         #IF(%FieldType = 'STRING' OR %FieldType = 'CSTRING' OR %FieldType = 'PSTRING' OR %FieldType = 'GROUP')
  171. LBL::%ArrayField::%Counter1   STRING(SIZE(%ReportLabelField)),DIM(%ReportLabel)
  172.                                                #<!%ReportLabelField Multi-up USE variable
  173.         #ELSE
  174. LBL::%ArrayField::%Counter1   REAL,DIM(%ReportLabel)
  175.                                                #<!%ReportLabelField Multi-up USE variable
  176.         #ENDIF
  177.       #ELSE
  178.         #SET(%BreakField,%ReportLabelField)
  179.         #INSERT(%RptFindFile)
  180.         #FIX(%File,%FoundFile)
  181.         #FIX(%Field,%ReportLabelField)
  182.         #IF(%FieldType = 'GROUP')
  183. LBL::%ReportLabelField   STRING(SIZE(%ReportLabelField)),DIM(%ReportLabel)
  184.                                                #<!%ReportLabelField Multi-up USE variable
  185.         #ELSE
  186. LBL::%ReportLabelField   LIKE(%ReportLabelField),DIM(%ReportLabel)
  187.                                                #<!%ReportLabelField Multi-up USE variable
  188.         #ENDIF
  189.       #ENDIF
  190.     #ENDFOR
  191.   #ENDIF
  192. #!
  193. #!***************************************************************************
  194. #GROUP(%RptRedirectGroup)                       #!Runtime report redirection
  195. #!
  196. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  197. #!│                            RptRedirectGroup            │Version: 3007.105│
  198. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  199. #!│Purpose:      Generates Report Redirection Code                           │
  200. #!│Called From:  Report Procedure                                            │
  201. #!│Assumptions:  None                                                        │
  202. #!│Inserts:      PrinterOffLineMsg                                           │
  203. #!│Symbols Set:  None                                                        │
  204. #!│Notes:        None                                                        │
  205. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  206. #!│Version   Comments                                                        │
  207. #!│────────  ────────────────────────────────────────────────────────────────│
  208. #!│3007.000  Release of CDD3 version 3007 templates                          │
  209. #!│3007.105  Replaced RETURNs with DO ProcedureReturn                        │
  210. #!└──────────────────────────────────────────────────────────────────────────┘
  211. #!
  212.   #IF(%RedirectProc)
  213. %RedirectProc                                  #<!Call redirection procedure
  214. CASE GLO:FileSpec                              #<!Detect redirection selection
  215. OF 'CANCEL'                                    #<!Cancel report requested
  216.   DO ProcedureReturn
  217.     #IF(%ViewProc)
  218. OF 'SCREEN'                                   #<!Screen view requested
  219.   TempPath = COMMAND('CLATMP',0)               #<!Get temporary file directory
  220.   IF TempPath                                  #<!CLATMP set?
  221.     SavePath = PATH()                          #<!Save current path
  222.     SETPATH(TempPath)                          #<!Set to temp file directory
  223.   END
  224.   LOOP                                         #<!Create temporary filename
  225.     X# += 1                                    #<! for screen report
  226.     TempFile = 'RPT' & FORMAT(X#,@N05) & '.$$$'
  227.     IF NOT Access(TempFile,0) THEN CYCLE ELSE BREAK. #<!Check existing file
  228.   END
  229.   IF TempPath                                  #<!CLATMP set?
  230.     IF SUB(CLIP(TempPath),-1,1) = '\'
  231.       TempFile = CLIP(TempPath) & TempFile     #<!Assign temporary filename
  232.     ELSE
  233.       TempFile = CLIP(TempPath) & '\' & TempFile #<!Assign temporary filename
  234.     END
  235.     SETPATH(SavePath)                          #<!Return to previous path
  236.   END
  237.   ReportDevice = TempFile
  238.   GLO:FileSpec = TempFile
  239.     #ELSE                                       #!Redirect w/o View Proc
  240. OF 'SCREEN'                                    #<!Screen view requested
  241.   DO ProcedureReturn                           #<! w/o View Procedure
  242.     #ENDIF
  243. ELSE                                           #<!All other report devices
  244.   ReportDevice = GLO:FileSpec                  #<! go to the device
  245.   TempFile = SUB(LEFT(UPPER(GLO:FileSpec)),1,3) #<!Get first three characters
  246.   IF (TempFile = 'LPT' OR TempFile = 'COM') AND NUMERIC(GLO:FileSpec[4])
  247.     IF TempFile = 'LPT' and NOT STATUS(GLO:FileSpec) #<!Check printer status
  248.       #INSERT(%PrinterOffLineMsg)
  249.       DO ProcedureReturn
  250.     END
  251.     GLO:FileSpec = ''                          #<!Disable viewing
  252.   END
  253.   TempFile = ''
  254. END
  255.   #ELSIF(%ViewProc)                             #!View w/o Redirect Proc
  256. TempFile = SUB(LEFT(UPPER(%ReportDevice)),1,3) #<!Get first three characters
  257. IF (TempFile = 'LPT' OR TempFile = 'COM') AND NUMERIC(SUB(LEFT(%ReportDevice),4,1))
  258.   IF TempFile = 'LPT' and NOT STATUS(%ReportDevice) #<!Check printer status
  259.     #INSERT(%PrinterOffLineMsg)
  260.     DO ProcedureReturn
  261.   END
  262.   GLO:FileSpec = ''                            #<!Disable viewing
  263. ELSE
  264.   GLO:FileSpec = ReportDevice                  #<!Set up filename for %ViewProc
  265. END                                            #<! port selections
  266. TempFile = ''
  267.   #ELSE                                          #!No View or Redirect Proc
  268. TempFile = SUB(LEFT(UPPER(%ReportDevice)),1,3) #<!Get first three characters
  269. IF (TempFile = 'LPT' OR TempFile = 'COM') AND NUMERIC(SUB(LEFT(%ReportDevice),4,1))
  270.   IF TempFile = 'LPT' and NOT STATUS(%ReportDevice) #<!Check printer status
  271.     #INSERT(%PrinterOffLineMsg)
  272.     DO ProcedureReturn
  273.   END
  274. END                                            #<! port selections
  275. TempFile = ''
  276.   #ENDIF
  277. #!
  278. #!***************************************************************************
  279. #GROUP(%RptGetLookupRecords)                    #!Get all lookup records
  280.   #FOR(%Secondary)                              #!%GetLookupFrom must be set
  281.     #IF(%SecondaryTo = %GetLookupFrom)          #! before #INSERT of this group
  282.       #IF(%SecondaryType = 'MANY:1')            #!Check for Lookup files
  283.         #FIX(%File,%SecondaryTo)
  284.         #FIX(%Relation,%Secondary)
  285.         #FOR(%RelationKeyField)
  286. %RelationKeyField = %RelationKeyFieldLink      #<!Assign linking field value
  287.         #ENDFOR
  288. GET(%Secondary,%RelationKey)                   #<!Lookup record
  289.         #FIX(%File,%Secondary)
  290. IF ERRORCODE() THEN CLEAR(%FilePre:Record).    #<!Clear record if unsuccessful
  291.         #IF(%ReportSaveExist)
  292.           #SET(%SaveFile,%Secondary)            #!Check for footer save fields
  293. #INSERT(%SaveFooterFields)
  294.         #ENDIF
  295.         #SET(%Temp,%GetLookupFrom)              #!Push GetLookupFrom files
  296.         #IF(NOT INSTRING(%Temp,%LookupFromQueue,1,1))
  297.           #SET(%LookupFromQueue,(%Temp & ',' & %LookupFromQueue))
  298.         #ENDIF
  299.         #SET(%GetLookupFrom,%Secondary)         #!Set up for next level
  300. #INSERT(%RptGetLookupRecords)                   #! and recursively get lookups
  301.         #SET(%GetLookupFrom,(SUB(%LookupFromQueue,1,INSTRING(',',%LookupFromQueue,1,1)-1)))
  302.         #SET(%LookupFromQueue,(SUB(%LookupFromQueue,LEN(%Temp)+2,LEN(%LookupFromQueue)-LEN(%Temp)+1)))
  303.                                                 #!Pop GetLookupFrom files
  304.       #ENDIF
  305.     #ENDIF
  306.   #ENDFOR
  307. #!
  308. #!***************************************************************************
  309. #GROUP(%RptGetRelatedRecords)                   #!Get all related records
  310. #FOR(%Secondary)                                #!%Parent must be set
  311.   #IF(%SecondaryTo=%Parent)               #! before #INSERT of this group
  312.     #IF(%SecondaryType = '1:MANY')              #!Check for children files
  313.       #FIX(%File,%Secondary)
  314.       #SET(%GroupBreakOnFile,%Null)
  315.       #SET(%GroupBreakCounter,%Null)
  316.       #FOR(%ReportGroup)
  317.         #FIX(%Field,%ReportGroup)
  318.         #SET(%GroupBreakCounter,(%GroupBreakCounter+1))
  319.         #IF(%Field)
  320.           #SET(%GroupBreakOnFile,%Field)
  321.           #BREAK
  322.         #ENDIF
  323.       #ENDFOR
  324.       #FIX(%File,%Parent)
  325.       #FIX(%Relation,%Secondary)
  326.       #SET(%HoldRelationKey,%RelationKey)
  327.       #FIX(%File,%Relation)
  328.       #FIX(%Key,%HoldRelationKey)
  329.       #FOR(%KeyField)
  330.         #SET(%LastSequence,%KeyFieldSequence)
  331.       #ENDFOR
  332.       #IF(%LastSequence='ASCENDING')
  333. CLEAR(%RelationPre:Record,-1)
  334.       #ELSE
  335. CLEAR(%RelationPre:Record,1)
  336.       #ENDIF
  337.       #FIX(%File,%Parent)
  338.       #FIX(%Relation,%Secondary)
  339.  
  340.     #FOR(%RelationKeyField)
  341.         #IF(%RelationKeyFieldLink)
  342. %RelationKeyField = %RelationKeyFieldLink      #<!Assign linking field value
  343.         #ELSE
  344.           #SET(%CurrentKeyField,%RelationKeyFieldLink)
  345.           #SET(%BeginClearing,%Null)
  346.           #FIX(%File,%Relation)
  347.           #FIX(%Key,%HoldRelationKey)
  348.           #FOR(%KeyField)
  349.             #IF(%KeyField=%CurrentKeyField)
  350.               #SET(%BeginClearing,'TRUE')
  351.             #ENDIF
  352.             #IF(%BeginClearing)
  353.               #IF(%KeyFieldSequence='ASCENDING')
  354. CLEAR(%KeyField,-1)                            #<!Clear ASCENDING key field
  355.               #ELSE
  356. CLEAR(%KeyField,1)                             #<!Clear DESCENDING key field
  357.               #ENDIF
  358.             #ENDIF
  359.           #ENDFOR
  360.           #BREAK
  361.         #ENDIF
  362.       #ENDFOR
  363.       #FIX(%File,%Parent)
  364.       #FIX(%Relation,%Secondary)
  365. %RelationPre::PRINTED = False                  #<!Set records printed flag
  366. SET(%RelationKey,%RelationKey)                 #<!Set to first related record
  367. LOOP                                           #<!Loop through %Secondary
  368.   NEXT(%Secondary)                             #<! getting each record
  369.   IF ERRORCODE() THEN ErrEndFileFlag# = 1 ELSE ErrEndFileFlag# = 0. #<!Flag EOF
  370.       #FIX(%File,%Secondary)
  371.       #SET(%CodePosition,(%FilePre&':FILTER'))
  372.   #INSERT(%RptRecordFilter)
  373.       #SET(%GetLookupFrom,%Secondary)
  374.   #INSERT(%RptGetLookupRecords)                 #!Get all Lookup records
  375.       #SET(%CodePosition,%Secondary)            #!Class = primary file
  376.   #INSERT(%ReportFormulas)                      #!Generate formulas
  377.       #IF(%GroupBreakOnFile)
  378.         #IF(%ReportSaveExist)
  379.           #SET(%SaveFile,%Secondary)            #!Check for footer save fields
  380.   #INSERT(%SaveFooterFields)
  381.         #ENDIF
  382.   #INSERT(%SecondaryGroupBreak)
  383.       #ELSE                                     #!No group break on this file
  384.         #IF(%ReportSaveExist)
  385.           #SET(%SaveFile,%Secondary)            #!Check for footer save fields
  386.   #INSERT(%SaveFooterFields)
  387.         #ENDIF
  388.         #SET(%IfWritten,%Null)
  389.         #FOR(%RelationKeyField)
  390.           #IF(%RelationKeyFieldLink)
  391.             #IF(%IfWritten)
  392.   OR %RelationKeyField <> %RelationKeyFieldLink | #<!Past related records?
  393.             #ELSE
  394.   IF %RelationKeyField <> %RelationKeyFieldLink |
  395.             #SET(%IfWritten,'TRUE')
  396.             #ENDIF
  397.           #ELSE
  398.             #BREAK
  399.           #ENDIF
  400.         #ENDFOR
  401.         #IF(%IfWritten)
  402.   OR ErrEndFileFlag#                           #<!  or EOF?
  403.         #ELSE
  404.   IF ErrEndFileFlag#                           #<!  or EOF?
  405.         #ENDIF
  406.     BREAK                                      #<!Break loop
  407.   END
  408.         #FIX(%File,%Secondary)
  409.         #SET(%CodePosition,(%FilePre&':FILTER'))
  410.   #INSERT(%RptRecordFilter)
  411.         #SET(%GetLookupFrom,%Secondary)
  412.   #INSERT(%RptGetLookupRecords)                 #!Get all Lookup records
  413.         #SET(%CodePosition,%Secondary)          #!Class = primary file
  414.   #INSERT(%ReportFormulas)                      #!Generate formulas
  415.       #ENDIF
  416.         #SET(%Parent,%Secondary)          #!Recursive call to this group
  417.   #INSERT(%RptGetRelatedRecords)                #!  to get next level deep
  418.       #IF(%DetailPrinted <> 'PRINTED')          #!If at lowest recursion level
  419.   #INSERT(%PrintDetail)                         #! insert PRINT(Rpt:Detail)
  420.   #INSERT(%RptAbortKey)                         #! and ESC key abort loop
  421.         #SET(%DetailPrinted,'PRINTED')          #!Set detail printed flag
  422.       #ENDIF
  423. END                                            #<!End %Secondary File Loop
  424.     #ENDIF
  425.   #ENDIF
  426. #ENDFOR
  427. #!
  428. #!***************************************************************************
  429. #GROUP(%PrintDetail)
  430.   #IF(%ReportLabel)
  431. #INSERT(%MultiUpLabelBuild)
  432.   #ENDIF
  433.   #SET(%TallyType,'ALL')                        #!For totals on ALL
  434. #INSERT(%TallyTotals)                           #!Tally total fields
  435.   #IF(%ReportDetailPre)
  436. %ReportDetailPre
  437.   #ENDIF
  438.   #IF(%ReportDetail)
  439. PRINT(%ReportPre:%ReportDetail)                #<!Print line item detail
  440.   #ENDIF
  441.   #IF(%ProgressScreen)
  442. DISPLAY                                       #<!Display report progress
  443.   #ENDIF
  444.   #IF(%ReportDetailPost)
  445. %ReportDetailPost
  446.   #ENDIF
  447.   #IF(%PageTotals)                              #!Any page total fields?
  448. IF SAV::LineCounter > %ReportLine              #<!Page overflow occurred?
  449.     #SET(%ResetTotalType,'PAGE')                #!Reset page totals
  450.   #INSERT(%ResetTotals)
  451.     #SET(%TallyType,'PAGE')                     #!Tally page totals
  452.   #INSERT(%TallyTotals)
  453. END
  454. SAV::LineCounter = %ReportLine                 #<!Save page overflow detect
  455.   #ENDIF
  456.   #IF(%ReportLabel)
  457. #INSERT(%MultiUpLabelReset)
  458.   #ENDIF
  459. #!
  460. #!***************************************************************************
  461. #GROUP(%RptTotalRoutines)                       #!Total field routines
  462.   #FOR(%ReportTotal)
  463.     #IF(%ReportTotalTally = 'PAGE')
  464.  
  465. Tally::PAGE::Totals  ROUTINE                   #<!Tallys on page break
  466.       #SET(%TallyType,'PAGE')
  467.   #INSERT(%DoTallyTotals)
  468.       #BREAK
  469.     #ENDIF
  470.   #ENDFOR
  471.   #FOR(%ReportTotal)
  472.     #IF(%ReportTotalTally = 'ALL')
  473.  
  474. Tally::ALL::Totals ROUTINE                     #<!Tallys on body detail
  475.       #SET(%TallyType,'ALL')
  476.   #INSERT(%DoTallyTotals)
  477.       #BREAK
  478.     #ENDIF
  479.   #ENDFOR
  480.   #FOR(%ReportGroup)
  481.     #FOR(%ReportTotal)
  482.       #IF(%ReportTotalTally = %ReportGroup)
  483.  
  484. Tally::%ReportTotalTally::Totals ROUTINE       #<!Tallys on group break
  485.         #SET(%TallyType,%ReportTotalTally)
  486.   #INSERT(%DoTallyTotals)
  487.         #BREAK
  488.       #ENDIF
  489.     #ENDFOR
  490.   #ENDFOR
  491.   #FOR(%ReportTotal)
  492.     #IF(%ReportTotalReset = 'PAGE')
  493.  
  494. Reset::PAGE::Totals ROUTINE                    #<!Resets on page break
  495.      #SET(%ResetTotalType,'PAGE')
  496.   #INSERT(%DoResetTotals)
  497.       #BREAK
  498.     #ENDIF
  499.   #ENDFOR
  500.   #FOR(%ReportTotal)
  501.     #IF(%ReportTotalReset = 'NONE')
  502.  
  503. Reset::NONE::Totals ROUTINE                    #<!Resets on report close
  504.      #SET(%ResetTotalType,'NONE')
  505.   #INSERT(%DoResetTotals)
  506.       #BREAK
  507.     #ENDIF
  508.   #ENDFOR
  509.   #FOR(%ReportGroup)
  510.     #FOR(%ReportTotal)
  511.       #IF(%ReportTotalReset = %ReportGroup)
  512.  
  513. Reset::%ReportTotalReset::Totals ROUTINE       #<!Resets on group break
  514.      #SET(%ResetTotalType,%ReportTotalReset)
  515.   #INSERT(%DoResetTotals)
  516.         #BREAK
  517.       #ENDIF
  518.     #ENDFOR
  519.   #ENDFOR
  520. #!
  521. #!***************************************************************************
  522. #GROUP(%DoTallyTotals)                          #!Tally total fields
  523.   #SET(%Counter1,%NULL)                         #!%TallyType must be set
  524.   #FOR(%ReportTotal)                            #! before #INSERT this group
  525.     #SET(%Counter1,(%Counter1 + 1))
  526.     #IF(%ReportTotalTally = %TallyType)
  527.       #IF(%ReportTotalType = 'SUM')
  528. %ReportPre:%ReportTotal += %ReportTotalField   #<!SUM total of %ReportTotalField
  529.       #ELSIF(%ReportTotalType = 'COUNT')
  530. %ReportPre:%ReportTotal += 1                   #<!COUNT total of %ReportTotalField
  531.       #ELSIF(%ReportTotalType = 'HIGH')
  532. IF %ReportTotalField > %ReportPre:%ReportTotal #<!HIGH value of %ReportTotalField
  533.   %ReportPre:%ReportTotal = %ReportTotalField
  534. END
  535.       #ELSIF(%ReportTotalType = 'LOW')
  536. IF %ReportTotal::Reset
  537.   %ReportTotal::Reset = False
  538.   %ReportPre:%ReportTotal = %ReportTotalField
  539. ELSE
  540.   IF %ReportTotalField < %ReportPre:%ReportTotal #<!LOW value of %ReportTotalField
  541.     %ReportPre:%ReportTotal = %ReportTotalField
  542.   END
  543. END
  544.       #ELSIF(%ReportTotalType = 'AVERAGE')
  545.         #IF(INSTRING('[',%ReportTotalField,1,1)) #!Check for array element
  546.           #SET(%ArrayField,(SUB(%ReportTotalField,1,INSTRING('[',%ReportTotalField,1,1)-1)))
  547. %ReportTotal::Cnt::%ArrayField::%Counter1 += 1 #<!AVERAGE of %ReportTotalField
  548. %ReportTotal::Sum::%ArrayField::%Counter1 += %ReportTotalField
  549. %ReportPre:%ReportTotal = %ReportTotal::Sum::%ArrayField::%Counter1 / %ReportTotal::Cnt::%ArrayField::%Counter1
  550.         #ELSE
  551. %ReportTotal::Cnt::%ReportTotalField += 1      #<!AVERAGE of %ReportTotalField
  552. %ReportTotal::Sum::%ReportTotalField += %ReportTotalField
  553. %ReportPre:%ReportTotal = %ReportTotal::Sum::%ReportTotalField / %ReportTotal::Cnt::%ReportTotalField
  554.         #ENDIF
  555.       #ENDIF
  556.     #ENDIF
  557.   #ENDFOR
  558. #!
  559. #!***************************************************************************
  560. #GROUP(%DoResetTotals)                          #!Reset total fields
  561.   #SET(%Counter1,%NULL)                         #!%ResetTotalType must be set
  562.   #FOR(%ReportTotal)                            #! before #INSERT this group
  563.     #SET(%Counter1,(%Counter1 + 1))
  564.     #IF(%ReportTotalReset = %ResetTotalType)
  565. %ReportPre:%ReportTotal = 0
  566.       #IF(%ReportTotalType = 'LOW')
  567. %ReportTotal::Reset = True
  568.       #ENDIF
  569.       #IF(%ReportTotalType = 'AVERAGE')
  570.         #IF(INSTRING('[',%ReportTotalField,1,1)) #!Check for array element
  571.           #SET(%ArrayField,(SUB(%ReportTotalField,1,INSTRING('[',%ReportTotalField,1,1)-1)))
  572. %ReportTotal::Cnt::%ArrayField::%Counter1 = 0
  573. %ReportTotal::Sum::%ArrayField::%Counter1 = 0
  574.         #ELSE
  575. %ReportTotal::Cnt::%ReportTotalField = 0
  576. %ReportTotal::Sum::%ReportTotalField = 0
  577.         #ENDIF
  578.       #ENDIF
  579.     #ENDIF
  580.   #ENDFOR
  581. #!
  582. #!***************************************************************************
  583. #GROUP(%TallyTotals)                            #!Tally total fields
  584.   #FOR(%ReportTotal)                            #!%TallyType must be set
  585.     #IF(%ReportTotalTally = %TallyType)         #! before #INSERT this group
  586. DO Tally::%TallyType::Totals                   #<!Tally %TallyType totals
  587.       #BREAK
  588.     #ENDIF
  589.   #ENDFOR
  590. #!
  591. #!***************************************************************************
  592. #GROUP(%ResetTotals)                            #!Reset total fields
  593.   #FOR(%ReportTotal)                            #!%ResetTotalType must be set
  594.     #IF(%ReportTotalReset = %ResetTotalType)    #! before #INSERT this group
  595. DO Reset::%ResetTotalType::Totals              #<!Reset %ResetTotalType totals
  596.       #BREAK
  597.     #ENDIF
  598.   #ENDFOR
  599. #!
  600. #!***************************************************************************
  601. #GROUP(%SaveFooterFields)                       #!Call footer save routines
  602.   #FOR(%ReportSave)                             #!%SaveFile must be set
  603.     #FOR(%ReportSaveField)                      #! before #INSERT this group
  604.       #SET(%BreakField,%ReportSaveField)
  605.       #INSERT(%RptFindFile)
  606.       #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  607.         #IF(%FoundFile = %SaveFile)             #!Check for save file
  608.           #FIX(%File,%SaveFile)
  609. DO Save::%FilePre::FooterFields                #<!Save %SaveFile footer fields
  610.           #SET(%Done,'YES')
  611.           #BREAK
  612.         #ELSE
  613.           #SET(%Done,%NULL)
  614.         #ENDIF
  615.       #ENDIF
  616.     #ENDFOR
  617.     #IF(%Done = 'YES')
  618.       #BREAK
  619.     #ENDIF
  620.   #ENDFOR
  621. #!
  622. #!***************************************************************************
  623. #GROUP(%SaveFooterRoutine)                      #!Rotate footer save fields
  624.   #SET(%Temp,(SUB(%TempQueue,1,INSTRING(',',%TempQueue,1,1)-1)))
  625.   #SET(%TempQueue,(SUB(%TempQueue,LEN(%Temp)+2,LEN(%TempQueue)-LEN(%Temp)+1)))
  626.   #IF(%Temp)
  627.     #FOR(%ReportSave)
  628.       #IF(%ReportSave <> 'PAGE')
  629.         #FOR(%ReportSaveField)
  630.           #SET(%BreakField,%ReportSaveField)
  631.           #INSERT(%RptFindFile)
  632.           #IF(%Temp = %FoundFile)
  633.             #FIX(%File,%FoundFile)
  634. Save::%FilePre::FooterFields ROUTINE           #<!Save footer fields
  635.             #SET(%SaveFile,%FoundFile)
  636.   #INSERT(%SaveFooterAssigns)
  637.             #SET(%GetAssigns,'YES')
  638.             #BREAK
  639.           #ELSE
  640.             #SET(%GetAssigns,%NULL)
  641.           #ENDIF
  642.         #ENDFOR
  643.       #ENDIF
  644.       #IF(%GetAssigns)
  645.         #BREAK
  646.       #ENDIF
  647.     #ENDFOR
  648. #INSERT(%SaveFooterRoutine)
  649.   #ENDIF
  650. #!
  651. #!***************************************************************************
  652. #GROUP(%SaveFooterAssigns)                      #!Rotate footer save fields
  653.   #SET(%Counter1,%NULL)
  654.   #SET(%Counter2,%NULL)
  655.   #FOR(%ReportSave)                             #!%SaveFile must be set
  656.     #SET(%Counter1,(%Counter1 + 1))
  657.     #FOR(%ReportSaveField)                      #! before #INSERT this group
  658.       #IF(%ReportSaveField <> %ReportPage)
  659.         #SET(%Counter2,(%Counter2 + 1))
  660.         #IF(INSTRING('[',%ReportSaveField,1,1)) #!Check for array element
  661.           #SET(%ArrayField,(SUB(%ReportSaveField,1,INSTRING('[',%ReportSaveField,1,1)-1)))
  662.         #ELSE
  663.           #SET(%ArrayField,%NULL)               #!Clear array flag
  664.         #ENDIF
  665.         #SET(%BreakField,%ReportSaveField)
  666.         #INSERT(%RptFindFile)
  667.         #FIX(%Secondary,%FoundFile)
  668.         #IF(%FoundFile = %SaveFile)
  669.           #IF(%ArrayField)                      #!Check for array element
  670. SAV2::%ReportSave::%ArrayField::%Counter1::%Counter2 = SAV1::%ReportSave::%ArrayField::%Counter1::%Counter2
  671. SAV1::%ReportSave::%ArrayField::%Counter1::%Counter2 = %ReportSaveField
  672.           #ELSE
  673. SAV2::%ReportSave::%ReportSaveField = SAV1::%ReportSave::%ReportSaveField
  674. SAV1::%ReportSave::%ReportSaveField = %ReportSaveField
  675.           #ENDIF
  676.         #ENDIF
  677.       #ENDIF
  678.     #ENDFOR
  679.   #ENDFOR
  680. #!
  681. #!***************************************************************************
  682. #GROUP(%PrintFooterFields)                      #!Set footer to print correct
  683. #!
  684. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  685. #!│                           PrintFooterFields            │Version: 3007.102│
  686. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  687. #!│Purpose:      Generate DOs to routines that save report values            │
  688. #!│Called From:  %GroupBreakFooter                                           │
  689. #!│Assumptions:  That %WhichFooter contains the field that the break is on   │
  690. #!│Inserts:      %RptFindFile (Find the file corresponding to a field)       │
  691. #!│Symbols Set:  None                                                        │
  692. #!│Notes:        None                                                        │
  693. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  694. #!│Version   Comments                                                        │
  695. #!│────────  ────────────────────────────────────────────────────────────────│
  696. #!│3007.000  Release of CDD3 version 3007 templates                          │
  697. #!│3007.102  Repaired ROUTINE name (was constructed as Print::%FilePre::...  │
  698. #!│          Should have been based on the Group Break name (%ReportSave).   │
  699. #!└──────────────────────────────────────────────────────────────────────────┘
  700. #!
  701.   #FOR(%ReportSave)                             #! before #INSERT this group
  702.     #IF(%ReportSave = %WhichFooter)             #!Check for save file
  703.       #SET(%BreakField,%ReportSave)
  704.       #INSERT(%RptFindFile)
  705.       #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  706. DO Print::%ReportSave::FooterFields            #<!Print correct footer fields
  707.         #BREAK
  708.       #ENDIF
  709.     #ENDIF
  710.   #ENDFOR
  711. #!
  712. #!***************************************************************************
  713. #GROUP(%PrintFooterRoutine)                     #!Set footer to print correct
  714. #!
  715. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  716. #!│                           PrintFooterRoutine           │Version: 3007.102│
  717. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  718. #!│Purpose:      Generate routines that save report values                   │
  719. #!│Called From:  Report #PROCEDURE                                           │
  720. #!│Assumptions:  None                                                        │
  721. #!│Inserts:      %RptFindFile (Find the file corresponding to a field)       │
  722. #!│Symbols Set:  None                                                        │
  723. #!│Notes:        None                                                        │
  724. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  725. #!│Version   Comments                                                        │
  726. #!│────────  ────────────────────────────────────────────────────────────────│
  727. #!│3007.000  Release of CDD3 version 3007 templates                          │
  728. #!│3007.102  Repaired ROUTINE name (was constructed as Print::%FilePre::...  │
  729. #!│          Should have been based on the Group Break name (%ReportSave).   │
  730. #!└──────────────────────────────────────────────────────────────────────────┘
  731. #!
  732.   #SET(%Counter1,%NULL)                         #!  footer field values
  733.   #SET(%Counter2,%NULL)
  734.   #FOR(%ReportSave)                             #! before #INSERT this group
  735.     #SET(%BreakField,%ReportSave)
  736.     #INSERT(%RptFindFile)
  737.     #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  738.       #FIX(%File,%FoundFile)
  739. Print::%ReportSave::FooterFields ROUTINE       #<!Print correct footer fields
  740.       #SET(%Counter1,(%Counter1 + 1))
  741.       #FOR(%ReportSaveField)                    #! before #INSERT this group
  742.         #SET(%Counter2,(%Counter2 + 1))
  743.         #SET(%BreakField,%ReportSaveField)
  744.         #INSERT(%RptFindFile)
  745.         #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  746.           #IF(INSTRING('[',%ReportSaveField,1,1)) #!Check for array element
  747.             #SET(%ArrayField,(SUB(%ReportSaveField,1,INSTRING('[',%ReportSaveField,1,1)-1)))
  748.   %ReportSaveField = SAV2::%ReportSave::%ArrayField::%Counter1::%Counter2
  749.           #ELSE
  750.   %ReportSaveField = SAV2::%ReportSave::%ReportSaveField
  751.           #ENDIF
  752.         #ENDIF
  753.       #ENDFOR
  754.     #ENDIF
  755.   #ENDFOR
  756. #!
  757. #!***************************************************************************
  758. #GROUP(%RestoreFooterFields)                    #!Restore changed footer
  759.   #FOR(%ReportSave)                             #! before #INSERT this group
  760.     #IF(%ReportSave = %WhichFooter)             #!Check for save file
  761.       #SET(%BreakField,%ReportSave)
  762.       #INSERT(%RptFindFile)
  763.       #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  764. DO Restore::%ReportSave::FooterFields          #<!Restore current footer fields
  765.       #BREAK
  766.       #ENDIF
  767.     #ENDIF
  768.   #ENDFOR
  769. #!
  770. #!***************************************************************************
  771. #GROUP(%RestoreFooterRoutine)                   #!Restore changed footer
  772.   #SET(%Counter1,%NULL)                         #!  footer field values
  773.   #SET(%Counter2,%NULL)
  774.   #FOR(%ReportSave)                             #! before #INSERT this group
  775.     #SET(%BreakField,%ReportSave)
  776.     #INSERT(%RptFindFile)
  777.     #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  778.  
  779. Restore::%ReportSave::FooterFields ROUTINE     #<!Restore current footer fields
  780.       #SET(%Counter1,(%Counter1 + 1))
  781.       #FOR(%ReportSaveField)                    #! before #INSERT this group
  782.         #SET(%Counter2,(%Counter2 + 1))
  783.         #SET(%BreakField,%ReportSaveField)
  784.         #INSERT(%RptFindFile)
  785.         #IF(INSTRING(%FoundFile,%SaveFilesQueue,1,1))
  786.           #IF(INSTRING('[',%ReportSaveField,1,1)) #!Check for array element
  787.             #SET(%ArrayField,(SUB(%ReportSaveField,1,INSTRING('[',%ReportSaveField,1,1)-1)))
  788.   %ReportSaveField = SAV1::%ReportSave::%ArrayField::%Counter1::%Counter2
  789.           #ELSE
  790.   %ReportSaveField = SAV1::%ReportSave::%ReportSaveField
  791.           #ENDIF
  792.         #ENDIF
  793.       #ENDFOR
  794.     #ENDIF
  795.   #ENDFOR
  796. #!
  797. #!***************************************************************************
  798. #GROUP(%ReportFormulas)                         #!Generate formula field code
  799.   #FOR(%Formula)                                #!%CodePosition must be set
  800.                                                 #! before #INSERT this group
  801.     #IF((UPPER(LEFT(%FormulaClass)) = UPPER(%CodePosition) OR %FormulaClass = %NULL) AND %FormulaType = 'COMPUTED')
  802. %Formula = %FormulaComputation                 #<!%FormulaDescription
  803.     #ENDIF
  804.   #ENDFOR
  805.   #FOR(%Formula)                                #!All computed fields before
  806.     #IF((UPPER(LEFT(%FormulaClass)) = UPPER(%CodePosition) OR %FormulaClass = %NULL) AND %FormulaType = 'CONDITION')
  807. IF %FormulaCondition                           #<!%FormulaDescription
  808.   %Formula = %FormulaTrue
  809. ELSE
  810.   %Formula = %FormulaFalse
  811. END
  812.     #ENDIF
  813.   #ENDFOR
  814. #!
  815. #!***************************************************************************
  816. #GROUP(%RptRecordFilter)                        #!Generate record filter code
  817.   #FOR(%Formula)                                #!%CodePosition must be set
  818.                                                 #! and must contain the file
  819.                                                 #! prefix followed by :FILTER
  820.     #IF(UPPER(LEFT(%FormulaClass)) = UPPER(%CodePosition))
  821.       #IF(%FormulaType = 'COMPUTED')
  822. IF NOT (%FormulaComputation)  |                #<!%FormulaDescription
  823.   AND NOT ErrEndFileFlag#                      #<!End of file?
  824.     CYCLE                                      #<!%File record filter
  825. END
  826.       #ELSE
  827. IF NOT (%FormulaCondition) |                   #<!%FormulaDescription
  828.   AND NOT ErrEndFileFlag#                      #<!End of file?
  829.     CYCLE                                      #<!%File record filter
  830. END
  831.       #ENDIF
  832.     #ENDIF
  833.   #ENDFOR
  834. #!***************************************************************************
  835. #GROUP(%GroupBreakNumber)                       #!Counts number of group
  836.   #SET(%GroupCounter,%NULL)                     #! breaks on %CurrentFile
  837.   #SET(%GroupFields,%NULL)                      #! and builds list of all the
  838.   #FOR(%ReportGroup)                            #! break fields for the file
  839.     #SET(%BreakField,%ReportGroup)
  840.     #INSERT(%RptFindFile)
  841.     #IF(%FoundFile = %CurrentFile)              #!Check breaks on current file
  842.       #SET(%GroupCounter,(%GroupCounter + 1))   #!Increment counter and add
  843.       #SET(%Temp,%ReportGroup)                  #! field to %GroupFields list
  844.       #SET(%GroupFields,(%Temp & ',' & %GroupFields))
  845.     #ENDIF
  846.   #ENDFOR
  847. #!***************************************************************************
  848. #GROUP(%PrimaryGroupBreak)                    #!Generates group breaks on
  849. #!
  850. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  851. #!│                            PrimaryGroupBreak           │Version: 3007.105│
  852. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  853. #!│Purpose:      Generates Primary Group Break code                          │
  854. #!│Called From:  Report PROCEDURE                                            │
  855. #!│Assumptions:  None                                                        │
  856. #!│Inserts:      FindGroupBreaks                                             │
  857. #!│              SaveFooterFields                                            │
  858. #!│Symbols Set:  None                                                        │
  859. #!│Notes:        None                                                        │
  860. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  861. #!│Version   Comments                                                        │
  862. #!│────────  ────────────────────────────────────────────────────────────────│
  863. #!│3007.000  Release of CDD3 version 3007 templates                          │
  864. #!│3007.105  Moved #INSERT to %SaveFooterFields to before the printing of    │
  865. #!│          Breaks.  The cade was after, and caused incorrect data to print │
  866. #!│          on Group Headers.                                               │
  867. #!└──────────────────────────────────────────────────────────────────────────┘
  868. #!
  869. #FIX(%File,%Primary)                            #! the %Primary file
  870. #FIX(%Key,%PrimaryKey)
  871. BreakLevel = 0                                 #<!Initialize group break flag
  872. #SET(%FirstCompareField,%Null)
  873. #IF(%SelectorAccess)                            #!If record selector
  874.   #SET(%IfWritten,%Null)                         #!Prepare For If Structure
  875.   #SET(%LastElementWritten,%Null)
  876.   #FOR(%KeyField)                                #!For each field in key
  877.     #IF(%KeyField=%KeyComponent)
  878.       #SET(%CompareAgainst,%ScopeValue)
  879.       #SET(%FirstCompareField,%KeyField)
  880.     #ELSE
  881.       #SET(%CompareAgainst,('BRK::'&%ScopeValue))
  882.     #ENDIF
  883.     #IF(%IfWritten)                              #!If the IF statement written
  884. OR %KeyComponent <> %CompareAgainst |            #<!Past Range Limits?
  885.     #ELSE                                        #!If IF not written yet
  886. IF %KeyComponent <> %CompareAgainst |            #<!Past Range Limits?
  887.     #ENDIF                                       #!END (If IF Written)
  888.     #IF(%FirstCompareField)
  889.       #BREAK
  890.     #ENDIF
  891.     #SET(%IfWritten,'TRUE')                      #!The IF statement written
  892.   #ENDFOR                                        #!END (For Relation Field)
  893. OR ErrEndFileFlag#                             #<! or End of file
  894. #ELSE
  895. IF ErrEndFileFlag#                             #<! or End of file
  896. #ENDIF
  897.   IF %FilePre::PRINTED                         #<!If %File Records printed
  898.     BreakLevel = 1                             #<! set break level to
  899.     DO Print::%FilePre::GroupFooters           #<! print last group footers
  900.   END
  901.   BREAK                                        #<!End the report
  902. END
  903. #INSERT(%FindGroupBreaks)
  904. #IF(%ReportSaveExist)
  905.   #SET(%SaveFile,%Primary)                      #!Check for footer save fields
  906. #INSERT(%SaveFooterFields)
  907. #ENDIF
  908. #FIX(%File,%Primary)
  909. IF NOT %FilePre::PRINTED                       #<!First time in?
  910.   BreakLevel = 1                               #<! set break level to
  911.   DO Print::%FilePre::GroupHeaders             #<! print first group headers
  912.   %FilePre::PRINTED = 1                        #<! and set recs printed flag
  913. ELSIF BreakLevel                               #<!Normal group break?
  914.   DO Print::%FilePre::GroupFooters             #<! print group footers
  915.   DO Print::%FilePre::GroupHeaders             #<! then group headers
  916. END
  917. #!***************************************************************************
  918. #GROUP(%FindGroupBreaks)
  919. #!
  920. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  921. #!│                             FindGroupBreaks            │Version: 3007.105│
  922. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  923. #!│Purpose:      Find and Write Group Break code                             │
  924. #!│Called From:                                                              │
  925. #!│Assumptions:  None                                                        │
  926. #!│Inserts:      None                                                        │
  927. #!│Symbols Set:  None                                                        │
  928. #!│Notes:        None                                                        │
  929. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  930. #!│Version   Comments                                                        │
  931. #!│────────  ────────────────────────────────────────────────────────────────│
  932. #!│3007.000  Release of CDD3 version 3007 templates                          │
  933. #!│3007.103  Repaired SAVE value restoration code (Now saves all fields up   │
  934. #!│          to and including first Report Group field)                      │
  935. #!│3007.105  Repaired SAVE value restoration code (Now saves all fields up   │
  936. #!│          to and including first Report Group field)                      │
  937. #!└──────────────────────────────────────────────────────────────────────────┘
  938. #!
  939. #SET(%GroupCounter,'1')
  940. #FOR(%ReportGroup)
  941.   #FIX(%Field,%ReportGroup)
  942.   #IF(%Field)
  943.     #SET(%IfWritten,%Null)                       #!Prepare For If Structure
  944.     #IF(%FirstCompareField)
  945.       #IF(%FirstCompareField=%Field)
  946.         #SET(%BeginWriting,'TRUE')
  947.       #ELSE
  948.         #SET(%BeginWriting,%Null)
  949.       #ENDIF
  950.     #ELSE
  951.       #SET(%BeginWriting,'TRUE')
  952.     #ENDIF
  953.     #FOR(%KeyField)
  954.       #IF(%BeginWriting)
  955.         #IF(UPPER(%KeyField)=UPPER(%ReportGroup))#!If this is last link field
  956.           #IF(%IfWritten)                        #!If the IF statement written
  957. OR BRK::%KeyField <> %KeyField                   #<!Past Range Limits?
  958.           #ELSE                                  #!If IF not written yet
  959.             #IF(%GroupCounter<>'1')
  960. ELSIF BRK::%KeyField <> %KeyField           #<!Past Range Limits?
  961.             #ELSE
  962. IF BRK::%KeyField <> %KeyField              #<!Past Range Limits?
  963.             #ENDIF
  964.             #SET(%IfWritten,'TRUE')              #!The IF statement written
  965.           #ENDIF                                 #!END (If IF Written)
  966.           #BREAK                                 #!Break out of loop
  967.         #ELSE                                    #!otherwise (Counter > 1)
  968.           #IF(%IfWritten)                        #!If the IF statement written
  969. OR BRK::%KeyField <> %KeyField |                 #<!Past Range Limits?
  970.           #ELSE                                  #!If IF not written yet
  971.             #IF(%GroupCounter<>'1')
  972. ELSIF BRK::%KeyField <>%KeyField |               #<!Past Range Limits?
  973.             #ELSE
  974. IF BRK::%KeyField <> %KeyField |                 #<!Past Range Limits?
  975.             #ENDIF
  976.             #SET(%IfWritten,'TRUE')              #!The IF statement written
  977.           #ENDIF                                 #!END (If IF Written)
  978.         #ENDIF                                   #!END (If Field Counter = 1)
  979.       #ELSIF(%KeyField=%FirstCompareField)
  980.         #SET(%BeginWriting,'True')
  981.       #ENDIF
  982.       #IF(UPPER(%KeyField)=UPPER(%ReportGroup))
  983.         #BREAK
  984.       #ENDIF
  985.     #ENDFOR
  986.     #IF(%IfWritten)
  987.   BreakLevel = %GroupCounter
  988.       #SET(%GroupCounter,(%GroupCounter+1))
  989.       #SET(%FirstCompareField,%ReportGroup)
  990.     #ENDIF
  991.   #ENDIF
  992. #ENDFOR
  993. END
  994. IF BreakLevel
  995.   #SET(%LastBreak,%Null)
  996.   #FOR(%ReportGroup)
  997.     #FIX(%Field,%ReportGroup)
  998.     #IF(%Field)
  999.       #SET(%LastBreak,%Field)
  1000.     #ENDIF
  1001.   #ENDFOR
  1002.   #FIX(%File,%BreakFile)
  1003.   #FOR(%KeyField)
  1004.     #IF(%KeyField=%LastBreak)
  1005.       #SET(%EndWriting,'TRUE')
  1006.     #ENDIF
  1007.   BRK::%KeyField = %KeyField                #<!Past Range Limits?
  1008.     #IF(%EndWriting)
  1009.       #BREAK
  1010.     #ENDIF
  1011.   #ENDFOR
  1012. END
  1013. #!***************************************************************************
  1014. #GROUP(%SecondaryGroupBreak)                     #!For Secondary files only
  1015. BreakLevel = 0                                   #<!Initialize group break flag
  1016.   #FIX(%File,%Parent)
  1017.   #FIX(%Relation,%Secondary)
  1018.   #SET(%IfWritten,%Null)
  1019.   #SET(%FirstCompareField,%Null)
  1020.   #FOR(%RelationKeyField)                        #! and build the code
  1021.     #IF(%RelationKeyFieldLink)
  1022.       #SET(%FirstCompareField,%RelationKeyField)
  1023.       #IF(%IfWritten)
  1024. OR %RelationKeyField <> %RelationKeyFieldLink   |#<!Past related records?
  1025.       #ELSE
  1026. IF %RelationKeyField <> %RelationKeyFieldLink   |#<!Past related records?
  1027.       #ENDIF
  1028.       #SET(%IfWritten,'TRUE')
  1029.     #ENDIF
  1030.   #ENDFOR
  1031.   #IF(%IfWritten)
  1032. OR ErrEndFileFlag#                             #<! or end of file?
  1033.   #ELSE
  1034. IF ErrEndFileFlag#                             #<! or end of file?
  1035.   #ENDIF
  1036.   IF %RelationPre::PRINTED                     #<!If %File Records printed
  1037.     BreakLevel = 1                             #<! set max break level to
  1038.     DO Print::%RelationPre::GroupFooters       #<! print last group footers
  1039.   END
  1040.   BREAK                                        #<!End %File file processing
  1041. END
  1042.   #SET(%ProcessingKey,%RelationKey)
  1043.   #FIX(%File,%Relation)
  1044.   #FIX(%Key,%ProcessingKey)
  1045. #INSERT(%FindGroupBreaks)
  1046. IF NOT %RelationPre::PRINTED                   #<!First time in?
  1047.   BreakLevel = 1                               #<! set break level to
  1048.   #SET(%LastProcessingField,%Null)
  1049.   #FIX(%File,%Secondary)
  1050.   #FOR(%ReportGroup)
  1051.     #FIX(%Field,%ReportGroup)
  1052.     #IF(%Field)
  1053.       #SET(%LastProcessingField,%Field)
  1054.     #ENDIF
  1055.   #ENDFOR
  1056.   #SET(%BeginWriting,%Null)
  1057.   #FIX(%Key,%ProcessingKey)
  1058.   #FOR(%RelationKeyField)
  1059.     #IF(%RelationKeyFieldLink=%Null)
  1060.   BRK::%RelationKeyField = %RelationKeyField #<!Save new break values
  1061.     #ENDIF
  1062.     #IF(%RelationKeyField=%LastProcessingField)
  1063.       #BREAK
  1064.     #ENDIF
  1065.   #ENDFOR
  1066.   DO Print::%RelationPre::GroupHeaders         #<! print first group headers
  1067.   %RelationPre::PRINTED = 1                    #<! and set recs printed flag
  1068. ELSIF BreakLevel
  1069.   DO Print::%RelationPre::GroupFooters         #<! print group footers
  1070.   DO Print::%RelationPre::GroupHeaders         #<! then group headers
  1071. END
  1072. #!
  1073. #!***************************************************************************
  1074. #GROUP(%BreakFooterRoutines)                   #!Build ROUTINES to print footers
  1075.   #SET(%TempFiles,%BreakFilesQueue)            #!Work through all files with
  1076.   #FOR(%ReportGroup)                           #! group breaks on them
  1077.     #SET(%Temp1,(SUB(%TempFiles,1,INSTRING(',',%TempFiles,1,1)-1)))
  1078.     #SET(%TempFiles,(SUB(%TempFiles,LEN(%Temp1)+2,LEN(%TempFiles)-LEN(%Temp1)+1)))
  1079.     #IF(NOT %Temp1)                            #!No files left in queue?
  1080.       #BREAK                                   #! end process
  1081.     #ENDIF
  1082.     #SET(%CurrentFile,%Temp1)                  #!Set up to get break fields
  1083.     #INSERT(%GroupBreakNumber)                 #! and count them
  1084.     #FIX(%File,%Temp1)                         #!Set up to work through
  1085.     #IF(%Primary = %File)                      #! %KeyField for all code
  1086.       #FIX(%Key,%PrimaryKey)
  1087.     #ELSE
  1088.       #FIX(%Secondary,%File)
  1089.       #FIX(%File,%SecondaryTo)
  1090.       #FIX(%Relation,%Secondary)
  1091.       #SET(%TempKey,%RelationKey)
  1092.       #FIX(%File,%Secondary)
  1093.       #FIX(%Key,%TempKey)
  1094.     #ENDIF
  1095.  
  1096. Print::%FilePre::GroupFooters ROUTINE          #<!Group Footers for %File file
  1097.     #IF(%ReportLabel)                          #!Check for labels with breaks
  1098.   #INSERT(%PrintDanglingLabels)
  1099.     #ENDIF
  1100.     #SET(%BreakCounter,%GroupCounter)
  1101.     #SET(%TempGroup,%GroupFields)
  1102.     #FOR(%KeyField)
  1103.       #SET(%Temp,(SUB(%TempGroup,1,INSTRING(',',%TempGroup,1,1)-1)))
  1104.       #SET(%TempGroup,(SUB(%TempGroup,LEN(%Temp)+2,LEN(%TempGroup)-LEN(%Temp)+1)))
  1105.       #FIX(%ReportGroup,%Temp)
  1106.       #IF(%ReportGroup <> %NULL)
  1107.   IF BreakLevel <= %BreakCounter               #<!Check group break level
  1108.     #INSERT(%GroupBreakFooter)
  1109.   END
  1110.       #ENDIF
  1111.       #SET(%BreakCounter,(%BreakCounter - 1))
  1112.       #IF(NOT %BreakCounter)
  1113.         #BREAK
  1114.       #ENDIF
  1115.     #ENDFOR
  1116.   #ENDFOR
  1117. #!
  1118. #!***************************************************************************
  1119. #GROUP(%BreakHeaderRoutines)
  1120.                  #!Build ROUTINES to print headers
  1121.   #SET(%TempFiles,%BreakFilesQueue)            #!Work through all files with
  1122.   #FOR(%ReportGroup)                           #! group breaks on them
  1123.     #SET(%Temp1,(SUB(%TempFiles,1,INSTRING(',',%TempFiles,1,1)-1)))
  1124.     #SET(%TempFiles,(SUB(%TempFiles,LEN(%Temp1)+2,LEN(%TempFiles)-LEN(%Temp1)+1)))
  1125.     #IF(NOT %Temp1)                            #!No files left in queue?
  1126.       #BREAK                                   #! end process
  1127.     #ENDIF
  1128.     #SET(%CurrentFile,%Temp1)                  #!Set up to get break fields
  1129.     #INSERT(%GroupBreakNumber)                 #! and count them
  1130.     #FIX(%File,%Temp1)                         #!Set up to work through
  1131.     #IF(%Primary = %File)                      #! %KeyField for all code
  1132.       #FIX(%Key,%PrimaryKey)
  1133.     #ELSE
  1134.       #FIX(%Secondary,%File)
  1135.       #FIX(%File,%SecondaryTo)
  1136.       #FIX(%Relation,%Secondary)
  1137.       #SET(%TempKey,%RelationKey)
  1138.       #FIX(%File,%Secondary)
  1139.       #FIX(%Key,%TempKey)
  1140.     #ENDIF
  1141.  
  1142. Print::%FilePre::GroupHeaders ROUTINE          #<!Group Headers for %File file
  1143.     #SET(%BreakCounter,'1')                    #!Check for labels with breaks
  1144.      #FOR(%KeyField)
  1145.       #IF(INSTRING(%KeyField,%GroupFields,1,1))
  1146.         #FIX(%ReportGroup,%KeyField)
  1147.   IF BreakLevel <= %BreakCounter               #<!Check group break level
  1148.     #INSERT(%GroupBreakHeader)
  1149.   END
  1150.         #IF(%BreakCounter = %GroupCounter)
  1151.           #BREAK
  1152.         #ENDIF
  1153.         #SET(%BreakCounter,(%BreakCounter + 1))
  1154.       #ENDIF
  1155.     #ENDFOR
  1156.   #ENDFOR
  1157. #!
  1158. #!***************************************************************************
  1159. #GROUP(%GroupBreakFooter)                       #!PRINT group footers
  1160.   #SET(%ThisReportGroup,%ReportGroup)           #!Save work Group
  1161.   #IF(%ReportSaveExist)
  1162.     #SET(%WhichFooter,%ThisReportGroup)         #!Ensure footer fields contain
  1163. #INSERT(%PrintFooterFields)                     #! correct values to print
  1164.   #ENDIF
  1165.   #FIX(%ReportGroup,%ThisReportGroup)           #!Fix to saved work Group
  1166.   #SET(%CodePosition,%ThisReportGroup)          #!Class = group break field
  1167. #INSERT(%ReportFormulas)                        #!Generate formulas
  1168.   #FIX(%ReportGroup,%ThisReportGroup)           #!Fix to saved work Group
  1169.    #IF(%ReportGroupFooterPre)
  1170. %ReportGroupFooterPre
  1171.    #ENDIF
  1172.    #IF(%ReportGroupFooter)
  1173. PRINT(%ReportPre:%ReportGroupFooter)           #<!Print group footer
  1174.      #IF(%ProgressScreen)
  1175. DISPLAY                                        #<!Display report progress
  1176.      #ENDIF
  1177.    #ENDIF
  1178.    #IF(%ReportGroupFooterPost)
  1179. %ReportGroupFooterPost
  1180.    #ENDIF
  1181.   #IF(%ReportSaveExist)
  1182.     #SET(%WhichFooter,%ThisReportGroup)         #!Ensure footer fields contain
  1183. #INSERT(%RestoreFooterFields)                   #!Restore saved footer fields
  1184.   #ENDIF
  1185.    #IF(%PageTotals)                             #!Any footer save fields?
  1186. IF SAV::LineCounter > %ReportLine              #<!Page overflow?
  1187.      #SET(%ResetTotalType,'PAGE')               #!Reset page totals
  1188.   #INSERT(%ResetTotals)
  1189.      #SET(%TallyType,'PAGE')                    #!Tally page totals
  1190.   #INSERT(%TallyTotals)
  1191. END
  1192. SAV::LineCounter = %ReportLine                 #<!Save line counter
  1193.   #ENDIF
  1194.   #SET(%TallyType,%ThisReportGroup)             #!Tally group total fields
  1195. #INSERT(%TallyTotals)
  1196.   #SET(%ResetTotalType,%ThisReportGroup)        #!Reset group total fields
  1197. #INSERT(%ResetTotals)
  1198. #!
  1199. #!***************************************************************************
  1200. #GROUP(%GroupBreakHeader)                       #!PRINT group header
  1201.   #SET(%ThisReportGroup,%ReportGroup)           #!Save work Group
  1202.   #IF(%ReportGroupHeaderPre)
  1203. %ReportGroupHeaderPre
  1204.   #ENDIF
  1205.   #IF(%ReportGroupHeader)
  1206. PRINT(%ReportPre:%ReportGroupHeader)           #<!Print group header
  1207.     #IF(%ProgressScreen)
  1208. DISPLAY                                        #<!Display report progress
  1209.     #ENDIF
  1210.   #ENDIF
  1211.   #IF(%ReportGroupHeaderPost)
  1212. %ReportGroupHeaderPost
  1213.   #ENDIF
  1214.    #IF(%PageTotals)                             #!Any footer save fields?
  1215. IF SAV::LineCounter > %ReportLine              #<!Page overflow?
  1216.      #SET(%ResetTotalType,'PAGE')               #!Reset page totals
  1217.   #INSERT(%ResetTotals)
  1218.      #SET(%TallyType,'PAGE')                    #!Tally page totals
  1219.   #INSERT(%TallyTotals)
  1220. END
  1221. SAV::LineCounter = %ReportLine                 #<!Save line counter
  1222.   #ENDIF
  1223. #!
  1224. #!***************************************************************************
  1225. #GROUP(%MultiUpLabelBuild)
  1226. SAV::LabelCounter += 1                         #<!Increment label counter
  1227.   #SET(%Counter1,%NULL)
  1228.   #FOR(%ReportLabelField)
  1229.     #SET(%Counter1,(%Counter1 + 1))
  1230.     #IF(INSTRING('[',%ReportLabelField,1,1)) #!Check for array element
  1231.       #SET(%ArrayField,(SUB(%ReportLabelField,1,INSTRING('[',%ReportLabelField,1,1)-1)))
  1232. LBL::%ArrayField::%Counter1[SAV::LabelCounter] = %ReportLabelField
  1233.     #ELSE
  1234. LBL::%ReportLabelField[SAV::LabelCounter] = %ReportLabelField
  1235.     #ENDIF
  1236.   #ENDFOR
  1237. IF SAV::LabelCounter < %ReportLabel
  1238.   CYCLE
  1239. END
  1240. #!
  1241. #!***************************************************************************
  1242. #GROUP(%MultiUpLabelReset)
  1243. SAV::LabelCounter = 0                          #<!Reset label counter
  1244.   #SET(%Counter1,%NULL)
  1245.   #FOR(%ReportLabelField)
  1246.     #SET(%Counter1,(%Counter1 + 1))
  1247.     #IF(INSTRING('[',%ReportLabelField,1,1)) #!Check for array element
  1248.       #SET(%ArrayField,(SUB(%ReportLabelField,1,INSTRING('[',%ReportLabelField,1,1)-1)))
  1249. CLEAR(LBL::%ArrayField::%Counter1)             #<!Reset label USE variable
  1250.     #ELSE
  1251. CLEAR(LBL::%ReportLabelField)                  #<!Reset label USE variable
  1252.     #ENDIF
  1253.   #ENDFOR
  1254. #!
  1255. #!***************************************************************************
  1256. #GROUP(%PrintDanglingLabels)
  1257. IF SAV::LabelCounter <> 0                      #<!If any labels left to print
  1258.     #IF(%ReportDetailPre)
  1259.   %ReportDetailPre
  1260.     #ENDIF
  1261.   PRINT(%ReportPre:%ReportDetail)              #<!Print last line item detail
  1262.     #IF(%ProgressScreen)
  1263.   DISPLAY                                      #<!Display report progress
  1264.     #ENDIF
  1265.     #IF(%ReportDetailPost)
  1266.   %ReportDetailPost
  1267.     #ENDIF
  1268.   #INSERT(%MultiUpLabelReset)
  1269. END
  1270. #!***************************************************************************
  1271. #GROUP(%RptAbortKey)
  1272.   #IF(%EscapeAbort)                             #!Enable ESC checked?
  1273. LOOP WHILE KEYBOARD()                          #<!If any keystrokes waiting
  1274.   ASK                                          #<! in the buffer, get them
  1275.   IF KEYCODE() = EscKey                        #<!Detect the ESC key
  1276.     DO ProcedureReturn
  1277.   END
  1278. END                                            #<!End abort key loop
  1279.   #ENDIF
  1280. #!
  1281. #!***************************************************************************
  1282. #GROUP(%RptSetFlags)                            #!Generation Condition flags
  1283.   #SET(%SelectorAccess,(%AccessMethod = 'Keyed Order' AND %KeyComponent <> %NULL))
  1284.   #FOR(%Secondary)                              #!Are there secondary files?
  1285.     #SET(%SecondaryExist,'YES')
  1286.     #BREAK
  1287.   #ENDFOR
  1288.   #FOR(%Formula)                                #!Are there Formulas?
  1289.     #SET(%FormulaExist,'YES')
  1290.     #BREAK
  1291.   #ENDFOR
  1292.   #FOR(%ReportGroup)                            #!Build queue of files that
  1293.     #SET(%BreakField,%ReportGroup)              #! have group breaks
  1294.     #INSERT(%RptFindFile)
  1295.     #SET(%Temp,%FoundFile)
  1296.     #IF(NOT INSTRING(%Temp,%BreakFilesQueue,1,1))
  1297.       #SET(%BreakFilesQueue,(%BreakFilesQueue & %Temp & ','))
  1298.     #ENDIF
  1299.     #SET(%ReportGroupExist,'YES')
  1300.   #ENDFOR
  1301.   #FOR(%ReportTotal)                            #!Are there Totals?
  1302.     #SET(%ReportTotalExist,'YES')
  1303.     #BREAK
  1304.   #ENDFOR
  1305.   #SET(%SaveFilesQueue,%NULL)
  1306.   #FOR(%ReportSave)                             #!Build list of files that
  1307.     #SET(%BreakField,%ReportSave)               #! have footers with fields
  1308.     #INSERT(%RptFindFile)                       #! from that file or are
  1309.     #SET(%BreakFile,%FoundFile)                 #! looked up from that file
  1310.     #FOR(%ReportSaveField)
  1311.       #SET(%BreakField,%ReportSaveField)
  1312.       #INSERT(%RptFindFile)
  1313.       #FIX(%Secondary,%FoundFile)
  1314.       #IF(%BreakFile = %FoundFile)
  1315.         #SET(%ReportSaveExist,'YES')            #!Set Flag
  1316.         #SET(%Temp,%FoundFile)
  1317.         #IF(NOT INSTRING(%Temp,%SaveFilesQueue,1,1))
  1318.           #SET(%SaveFilesQueue,(%SaveFilesQueue & %Temp & ','))
  1319.         #ENDIF
  1320.       #ELSIF(%SecondaryTo = %BreakFile AND %SecondaryType = 'MANY:1')
  1321.         #SET(%ReportSaveExist,'YES')            #!Set flag
  1322.         #SET(%Temp,%FoundFile)
  1323.         #IF(NOT INSTRING(%Temp,%SaveFilesQueue,1,1))
  1324.           #SET(%SaveFilesQueue,(%SaveFilesQueue & %Temp & ','))
  1325.         #ENDIF
  1326.       #ENDIF
  1327.     #ENDFOR
  1328.   #ENDFOR
  1329.   #FOR(%ReportTotal)                            #!Detect any PAGE total fields
  1330.     #IF(%ReportTotalReset = 'PAGE')
  1331.       #SET(%PageTotals,'YES')                   #!Set flag
  1332.       #BREAK
  1333.     #ELSIF(%ReportTotalTally = 'PAGE')
  1334.       #SET(%PageTotals,'YES')                   #!Set flag
  1335.       #BREAK
  1336.     #ENDIF
  1337.   #ENDFOR
  1338. #!
  1339. #!***************************************************************************
  1340. #GROUP(%RptFindFile)                            #!Find file from field prefix
  1341.   #SET(%FoundFile,%NULL)
  1342.   #FOR(%File)
  1343.     #IF(UPPER(%FilePre) = UPPER(SUB(%BreakField,1,INSTRING(':',%BreakField,1,1)-1)))
  1344.       #SET(%FoundFile,%File)
  1345.       #BREAK
  1346.     #ENDIF
  1347.   #ENDFOR
  1348. #!
  1349. #!***************************************************************************
  1350. #GROUP(%ReportErrorCheck)
  1351.   #SET(%ErrorMessage,(%Procedure & ' ERROR:'))
  1352.   #IF(%Primary = %NULL)                         #!No File Schematic?
  1353.     #ERROR(%ErrorMessage)
  1354.     #ERROR(' You MUST define a Primary File in the File Schematic.')
  1355.   #ENDIF
  1356.   #IF(%KeyComponent)
  1357.     #FIX(%File,%Primary)
  1358.     #FIX(%Key,%PrimaryKey)
  1359.     #FOR(%KeyField)
  1360.       #IF(%KeyField = %KeyComponent)
  1361.         #SET(%FoundComponent,'YES')
  1362.         #BREAK
  1363.       #ENDIF
  1364.     #ENDFOR
  1365.     #IF(%FoundComponent = %NULL)                #!Range limit on wrong Key?
  1366.       #ERROR(%ErrorMessage)
  1367.       #ERROR('  Range Limit Field must be a component of ')
  1368.       #ERROR('  the Primary file Access Key.')
  1369.     #ENDIF
  1370.     #IF(%ScopeValue = %NULL)                    #!Range limit w/o Range Value
  1371.       #ERROR(%ErrorMessage)
  1372.       #ERROR('  Must define a Range Value Field')
  1373.     #ELSIF(%KeyComponent = %ScopeValue)         #!Range limit == Range Value
  1374.       #ERROR(%ErrorMessage)
  1375.       #ERROR('  Range Value Field and Range Limit Field')
  1376.       #ERROR('  must be separate fields.')
  1377.     #ENDIF
  1378.   #ENDIF
  1379. #!
  1380. #CHAIN('Warnings.TPX')
  1381.